<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class LoginController extends Controller{
	private $userModel;
	public function __init(){
		$this->userModel = new \Common\Model\User;
	}
    //登陆
    public function index(){
    	if(IS_POST){
    		if(!$this->userModel->login()) View::error($this->userModel->getError());
			View::success('登陆成功，返回首页',U('Index/index'));
			/*$str = <<<str
			<script>
				history.go(-2);
			</script>
str;*/
			echo $str;
    	}
       	View::make();
    }
//	退出
	public function quit(){
		session_unset();
		session_destroy();
		go(U('Index/index'));
	}
//	登陆名验证
	public function loginname(){
		if(IS_POST){
			$username = Q('post.username');
			$user = $this->userModel->where("username = '{$username}'")->find();
			if($user){
				echo TRUE;
			}else{
				echo FALSE;
			}
		}
	}
//	密码验证
	public function lpwd(){
		if(IS_POST){
			$uname = Q('post.username');
			$upwd = Q('post.pwd','','md5');
			$userData = $this->userModel->where("username = '{$uname}'")->find();
			if($userData){
				$pwd = $userData['password'];
				if($upwd==$pwd){
					echo json_encode(array('status'=>TRUE));
				}else{
					echo json_encode(array('status'=>FALSE));
				}
			}else{
				echo json_encode(array('status'=>FALSE));
			}
		}
	}
	
	
	
}
